package com.gaoyi.websocket.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import sun.misc.BASE64Encoder;

import java.util.Date;

//安全策略
@Component
@Slf4j
public class SecurityTokenKey {

   private static final char chars[] = {'y','i','p','a','r','t','v','n','c','z'};

    public static String timeToStr(){
        String str = String.valueOf(new Date().getTime());
        String strArray[] =  str.substring(0,9).split("");

        char chars[] = {'y','i','p','a','r','t','v','n','c','z'};
        char box[] = new char[strArray.length];
        for (int i = 0; i < strArray.length; i++) {
            box[i] = chars[Integer.parseInt(strArray[i])];
        }
        String base64 = new BASE64Encoder().encodeBuffer(new String(box).getBytes()).replaceAll("\r|\n", "");
        return base64;
    }
}
